<template>
  <div>
    <van-nav-bar left-text="返回" right-text="分享" title="评论详情" left-arrow @click-left="onClickLeft">
      <template #right>
        <van-icon name="share-o" size="18" v-model:show="showShare" title="立即分享给好友" :options="options" @select="onSelect"
          @click="showShare = true" />
      </template>
    </van-nav-bar>
    <van-share-sheet v-model:show="showShare" title="立即分享给好友" :options="options" @select="onSelect" />
    <!-- 内容区域   -->
    <div style="display: flex;margin-top: 20px;">
      <div class="avatar">
        <img src="/img/cp/comment01.jpg" alt="">
      </div>
      <div class="info">
        <div>
          <div class="user">
            <div>
              <span>{{ bata.user_name }}</span>
              <div class="vip">
                <i class="iconfont icon-vip5"></i>
              </div>
            </div>
            <div>
              发布时间： {{ moment(bata.content_time).format("YYYY-MM-DD HH:mm:ss") }}
            </div>
          </div>
        </div>
      </div>
    </div>
    <!-- 内容区域       -->
    <div class="text">
      <span>{{ bata.content_text }} </span>
    </div>
    <div class="pic-box">
      <div class="pic-item" v-for="(item, i) in batacover" :key="i">
        <van-image class="pic" @click.native="previewImage(i)" :src="item" fit="cover" radius="6">
        </van-image>
      </div>
      <!-- <span>+{{ more }}</span> -->
      <!-- 评论区域 -->
    </div>
    <div class="pldb">全部回复 · {{ batason.length }}</div>
    <div style="margin-bottom: 30px;">
      <div v-for="(item, i) in batason" :key="i">
        <!-- 用户信息栏 -->
        <div class="user1">
          <div>
            <van-image round width="2rem" height="2rem" fit="cover"
              src="https://fastly.jsdelivr.net/npm/@vant/assets/cat.jpeg" />
          </div>
          <div class="name">
            <p> {{ item.reply_name }}</p>
          </div>
        </div>
        <!-- 评论详情 -->
        <div class="plq">
          {{ item.reply_text }}
        </div>

      </div>
    </div>
  </div>
  <van-cell @click="show = true">
    <div class="pl">写评论</div>
  </van-cell>
  <!-- 评论 -->
  <van-action-sheet v-model:show="show" title="回复">
    <van-cell-group inset>
      <van-field v-model="message" rows="4" autosize type="textarea" placeholder="请输入留言" />
      <van-button type="primary" size="large" style="margin-bottom: 15px;" @click="huiFu">发布评论</van-button>
    </van-cell-group>
  </van-action-sheet>
</template>
<script>
import { createApp, ref, reactive, onMounted, route } from 'vue';
import { showPopup, showToast, ActionSheet, Field, CellGroup, Button, image, showImagePreview, previewImage, Image as VanImage } from 'vant';
import 'vant/es/image-preview/style';
import httpApi from '@/http';
import { useRoute } from 'vue-router';
import { useStore } from 'vuex';
import moment from 'moment'
export default {
  setup() {
    const store = useStore()
    const route = useRoute()
    const app = createApp();
    const show = ref(false);
    const type = route.params.id
    console.log(type)
    const showPopup = () => {
      show.value = true;
    };
    const onClickLeft = () => history.back();
    const showShare = ref(false);
    const onSelect = (option) => {
      showToast(option.name);
      showShare.value = false;
    };
    const options = [
      { name: '微信', icon: 'wechat' },
      { name: '微博', icon: 'weibo' },
      { name: '复制链接', icon: 'link' },
      { name: '分享海报', icon: 'poster' },
      { name: '二维码', icon: 'qrcode' },
    ];



    // const urls = ref([]);
    // const srcs = reactive(
    //   urls.filter((value, index) => {
    //     return index < 3
    //   })
    //   );
    //   const more = ref(
    //     urls.length 
    //     );

    const previewImage = function (index) {
      showImagePreview({ images: batacover, startPosition: index })
    };
    const bata = ref({});
    const batason = ref([]);
    const batacover = reactive([]);
    onMounted(() => {
      httpApi.liveApi.queryBylistid({ page: 1, pagesize: 10, content_id: type }).then((res) => {
        console.log("加载详情：", res);
        bata.value = res.data.data.result[0]
        console.log(bata.content_text)
        batacover.splice(0, batacover.length, ...res.data.data.result[length].content_cover.split(";"))
        console.log(batacover)
      });
      httpApi.liveApi.queryByReplylist({ reply_fid: type }).then((res) => {
        console.log("加载详情：", res);
        console.log(type)
        batason.value = res.data.data.result
        console.log(batason.value.length, 'sss')

      });

    });
    const message = ref('')
    const huiFu = function () {
      let params = {
        reply_name: store.state.user.user_name,
        reply_text: message.value,
        reply_fid: type,
        reply_cover: store.state.user.user_cover,
      }
      httpApi.liveApi.queryByReply(params).then((res) => {
        console.log("加载详情：", res);
        if (res.data.code == 200) {
          show.value = false
          alert('评论成功！')
          httpApi.liveApi.queryByReplylist({ reply_fid: type }).then((res) => {
            batason.value = res.data.data.result
          });
        }
      });
    }
    return {
      options,
      onClickLeft,
      onSelect,
      showShare,
      showPopup,
      show,
      ActionSheet,
      Field,
      CellGroup,
      Button,
      image,
      previewImage,
      reactive,
      VanImage,
      bata,
      route,
      batacover,
      moment,
      huiFu,
      message,
      batason


    };
  },
};
</script>
<style lang="scss" scoped>
.pl {
  width: 70%;
  background-color: rgba(82, 157, 230, );
  border-radius: 15px;
  position: fixed;
  bottom: 10%;
  z-index: 999;
  text-align: center;
  margin: 0 40px;
  height: 30px;
  line-height: 30px;
  color: white;
  font-size: 15px;
}

.avatar {
  margin-left: 20px;

  >img {
    width: 40px;
    height: 40px;
    border-radius: 50%;
  }
}

.info {
  margin-left: 15px;

  .user {
    height: 40px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    margin-bottom: 10px;

    >div:nth-child(1) {
      display: flex;
      align-items: center;

      >span {
        font-size: 15px;
        font-weight: bold;
        margin-right: 3px;
      }

      .vip {
        display: flex;
        align-items: center;
        justify-content: center;
        width: 14px;
        height: 14px;
        border-radius: 3px;
        background-color: #42BAFC;

        >i {
          font-size: 16px;
          color: #fff;
          text-shadow: 0.5px 0.5px rgba(0, 0, 0, .5);
          display: inline-block;
        }
      }
    }

    >div:nth-child(2) {
      font-size: 12px;
      color: #909090;
    }
  }
}

.text {
  text-indent: 2rem;
  margin: 15px 10px;
  letter-spacing: 1px;

}

.pic-box {
  display: flex;
  justify-content: space-between;
  position: relative;
  margin: 15px 10px;

  >.pic-item {
    width: calc((100% - 10px) / 2);
    height: 100px;

    >.pic {
      width: 100%;
      height: 100%;
      object-fit: cover;
    }
  }

  >span {
    display: flex;
    justify-content: center;
    align-items: center;
    width: 32px;
    height: 32px;
    background-color: rgba(0, 0, 0, .5);
    color: #f9f8f7;
    font-size: 15px;
    font-weight: 400;
    border-end-end-radius: 6px;
    position: absolute;
    right: 0;
    bottom: 0;
  }
}

.user1 {
  display: flex;
  margin: 20px 15px;
  height: 32px;

  >.name {
    font-size: 12px;
    margin-left: 10px;

    >:last-child {
      color: grey;
    }
  }
}

.pldb {
  text-align: center;
  font-size: 18px;
  font-weight: bold;
  border-bottom: 1px solid gray;
  padding-bottom: 10px;
}

.plq {
  margin: 5px 15px;
  font-size: 13px;
}
</style>